package oppsa.util;


public class ConnectionFactory{

    //static reference to itself
    private static ConnectionFactory instance = new ConnectionFactory();
    private InterfaceConnection MysqlConnection=null;
    private InterfaceConnection HsqlDBConnection=null;
     
    public static InterfaceConnection getConnection(String connectionType) {
        return instance.createConnection(connectionType);
    }
    
    
    public InterfaceConnection createConnection(String connectionType)
   {
          //Some error checking
        switch(connectionType)
        {   
            case Constants.MYSQL:
                 return createMysqlConnection();
            case Constants.HSQLDB:
                 return createHSQLDBConnection();

            default:
            	return null;
        }
		
   }

   // MysqlConnection, HsqlDBConnection implement interfaceConnection
   public InterfaceConnection createMysqlConnection()
   {
	   if(MysqlConnection==null){
		   MysqlConnection = new MysqlConnection();
	   }
       return MysqlConnection;
   }

   public InterfaceConnection createHSQLDBConnection()
   {
	   if(HsqlDBConnection==null){
		   HsqlDBConnection = new HsqlDBConnection();
	   }
       return HsqlDBConnection;
   }
    
    
}